#!/bin/sh

export VENV_ROOT=`pwd`
export ESMOND_ROOT=${VENV_ROOT}/devel
export ESMOND_CONF=${ESMOND_ROOT}/esmond-devel.conf
export DJANGO_SETTINGS_MODULE=esmond.settings

# create a dummy TSDB
if [ ! -d ${ESMOND_ROOT}/tsdb-data ]; then
    mkdir ${ESMOND_ROOT}/tsdb-data
    touch ${ESMOND_ROOT}/tsdb-data/TSDB
fi

# create the virtualenv
virtualenv --prompt="(esmond)" .
. bin/activate

# XXX(jdugan) FreeBSD hack look for headers and libraries in /usr/local
# ObRant: WTF is with distutils/setuputils/pip not offerring a way to handle this?!?
# ObRantRant: OR maybe it's crappy behaviour on the part of pysqlite?  dunno
if [ x`uname` = x"FreeBSD" ]; then
    echo patching pysqlite to build under FreeBSD
    pip install --no-install pysqlite
    echo 'include_dirs=/usr/local/include' >> build/pysqlite/setup.cfg
    echo 'library_dirs=/usr/local/lib' >> build/pysqlite/setup.cfg
fi

pip install -r requirements.txt

cat <<EOF > esmond.env
export ESMOND_ROOT=${ESMOND_ROOT}
export ESMOND_CONF=${ESMOND_CONF}
export ESMOND_CLUSTER_CONF=${ESMOND_CLUSTER_CONF}
export ESMOND_TESTING=1
export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
export VENV_ROOT=${VENV_ROOT}
. ${VENV_ROOT}/bin/activate
EOF

echo environment variables and activation put in ${VENV_ROOT}/esmond.env:
cat ${VENV_ROOT}/esmond.env
